<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <style>
        .prizeconfirm .layui-layer-btn {
            height:50%;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .prizeconfirm .layui-layer-btn .layui-layer-btn0{
            border: 1px solid #dedede;
            background-color: #fff;
            color: #333;
            border-radius: 2px;
        }
        .prizeconfirm .layui-layer-content{
            display: none;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" value="{$info.id}">
    <div class="layui-form-item">
        <label class="layui-form-label required">活动名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" value="{$info.title}" lay-reqtext="活动名称不能为空" placeholder="请输入活动名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline">
            <input type="text" name="start_time" id="start_time" value="{$info.start_time}" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">下架时间</label>
            <div class="layui-input-inline">
                <input type="text" name="end_time" id="end_time" value="{$info.end_time}" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">活动说明</label>
        <div class="layui-input-block">
            <textarea name="detail" class="layui-textarea"  lay-verify="required" placeholder="请输入活动说明">{$info.detail}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status"   value="{$info.status}" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭" {if condition='$info.status==1'}checked=""{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">奖项设置</label>
        <div class="layui-input-block">
            <button class="layui-btn" onclick="createPrize(1)">创建奖项</button>
        </div>
    </div>
    <div class="layui-form-item" id="prize_table">

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script src="/static/admin/prize.js"></script>
<script>
    $(function(){
        getsPrizeList(1);
    })
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate=layui.laydate,
            $ = layui.$;
        // 上架开始日期
        var insShelf = laydate.render({
            elem: '#start_time'
            , min: 0
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insUnder.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                //insUnder.config.elem[0].focus();
            }
        });
        //上架结束日期
        var insUnder = laydate.render({
            elem: '#end_time'
            , min: 0
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                insShelf.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            if(this.checked){
                this.value=1;
            }else{
                this.value=2;
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data.field.status = data.field.status ? 1 : 2;
            $.ajax({
                url: "/admin/Active/roulette_write?action=ajax",
                type: 'post',
                async: true,
                data: data.field,
                dataType: 'json',
                success: function (res) {
                    if(res.status){
                        parent.layer.msg("操作成功!", {icon:1,time: 1000}, function () {
                            //重新加载父页面
                            parent.location.reload();
                        });
                        return;
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>